{% extends "layout.html" %}
{% block title %}策略监控{% endblock %}
{% block head %}
    {{ super() }}


{% endblock %}
{% block content %}



    <div ng-app="loginapp">

        <acountdialog></acountdialog><!--账户管理对话框 -->


        <!--策略表单-->
        <div ng-controller="strategCtrl">
            <br>
            <form class="form-inline" role="form" id="straForm">

                <div class="form-group">
                    <!--策略-->
                    <select ng-init="strategForm.selectedstrategName = strategNames[0]"
                            ng-model="strategForm.selectedstrategName" ng-options="x for x
                                in strategNames" ng-change="strategChange()" class="form-control"></select>
                    <!--映射合约-->
                    <select ng-init="strategForm.selectedinstrumentName=instruments[0]"
                            ng-model="strategForm.selectedinstrumentName" ng-options="x for x
                                    in instruments" class="form-control"></select>
                    <!--下单合约-->
                    <select ng-init="strategForm.selectedmappingstrument=instruments[0]"
                            ng-model="strategForm.selectedmappingstrument" ng-options="x for
                                    x in instruments" class="form-control"></select>


                    <label for="Zhouqi" class="form-control">周期</label>
                    <input type="text" class="form-control " ng-model="strategForm.Zhouqi" placeholder="请输入周期">
                    <select ng-model="strategForm.selectedIntervalType" ng-options="x for (x, y) in intervalTypes"
                            class="form-control">

                    </select>
                    <label for="name">参数</label>
                    <input ng-model="strategForm.strategParameter" type="text" class="form-control" name="canshuid"
                           id="canshuid">
                          <!--交易所-->
                    <select ng-init="strategForm.selectedstrategExcange = ExcangeNames[0]"
                            ng-model="strategForm.selectedstrategExcange" ng-options="x for x
                                in ExcangeNames"  class="form-control"></select>
                </div>

                <button type="button" class="btn btn-default" ng-click="submitAddFun()">提交</button>
            </form>
        </div>


        <!--策略table-->
        <div ng-controller="strategTableCtrl as strategNgTa">
            <script type="text/ng-template" id="strategNaTaCheckbox.html">
                <input type="checkbox" ng-model="strategNgTa.checkboxes.checked" class="select-all" value=""/>
            </script>
            <strategyconfigdialog></strategyconfigdialog><!--策略配置对话框-->
            <hr style="margin-bottom: 0px;">
            <div class="row">
                <div class="col-md-3" style="margin-top: 18px;">
                    <button type="button" class="btn btn-default" ng-click="allLoad()">加载</button>
                    <button type="button" class="btn btn-default" ng-click="alltrading('True')">启动</button>
                    <button type="button" class="btn btn-default" ng-click="alltrading('False')">停止</button>
                    <button type="button" class="btn btn-default"
                            onclick="window.open('{{ url_for('showPositionCheck') }}')">仓位检查
                    </button>
                </div>
                <div class="col-md-9">
                    <div class="alert alert-success" style="margin-bottom: 0px;margin-top: 5px;"
                         ng-init="messageText='欢迎使用金字塔量化策略执行系统'"><p ng-bind="messageText"></p></div>
                </div>
            </div>

            <!--table-primary 表头标题变成绿色-->
            <table ng-table class="table table-condensed table-bordered table-striped">
                <colgroup>
                    <col width="6%"/>
                    <col width="4%"/>
                    <col width="3%"/>
                    <col width="3%"/>
                    <col width="4%"/>
                    <col width="3%"/>
                    <col width="4%"/>
                    <col width="25%"/>
                    <col width="3%"/>
                    <col width="5%"/>
                    <col width="10%"/>
                    <col width="10%"/>

                </colgroup>
                <tr ng-repeat="row in simplieList">
                    {%raw%}
                    <td header="'strategNaTaCheckbox.html'"><input type="checkbox"
                                                                   ng-model="strategNgTa.checkboxes.items[row.id]"/>
                        {{row.id}}
                    </td>
                    <td title="'策略'">{{row.Strategy}}</td>
                    <td title="'交易所'">{{row.Excange}}</td>
                    <td title="'合约'">{{row.Instrument}}</td>
                    <td title="'映射合约'">{{row.Mappinginstrument}}</td>
                    <td title="'周期'">{{row.Interval}}</td>
                    <td title="'周期类型'">{{row.IntervalType}}</td>
                    <td title="'参数'">{{row.Params| textLengthSet:true:80:' ...' }}</td>
                    <td title="'策略仓'">多<span class="text-danger">{{ row.Position['多'] }}</span>
                        空<span class="text-success">{{ row.Position['空'] }}</span></td>
                    <td title="'账户'">{{row.Investors}}</td>
                    <td title="'操作'">
                        <button type="button" ng-disabled="row.status=='未加载'" class="btn btn-info"
                                ng-click="showK(row, $event)">详细
                        </button>
                        <button type="button" class="btn btn-danger" ng-click="peiZhi(row)">配置</button>
                        <button type="button" class="btn btn-danger" ng-click="zdTableRemove(row, $event)">删除</button>
                    </td>
                    <td title="'备用'"><span ng-class="row.statusClass">{{ row.status }}</span></td>
                    {%endraw%}
                </tr>

            </table>

        </div>

        <hr style="margin-top:10px">
        <!--账户报单table 持仓查询-->
        <div ng-controller="userinfoTableCtrl  as demo">

            <ul id="myTab" class="nav nav-tabs">
                <li class="active">
                    <a href="#home" data-toggle="tab">
                        账户情况
                    </a>
                </li>
                <li>
                    <a href="#ios" data-toggle="tab">
                        持仓情况
                    </a>
                </li>


                  <li>
                    <a href="#orderlisttab" data-toggle="tab">
                        委托单
                    </a>
                </li>

                <li>
                    <a href="#tradetab" data-toggle="tab">
                        成交记录
                    </a>
                </li>



                   <li class="dropdown">
                    <a href="#" id="myTabDrop1" class="dropdown-toggle"
                       data-toggle="dropdown">
                        测试的
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
                        <li><a href="#jmeter" tabindex="-1" data-toggle="tab">测试1</a></li>
                        <li><a href="#ejb" tabindex="-1" data-toggle="tab">测试2</a></li>
                    </ul>
                </li>
            </ul>

            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade in active" id="home">
                    <!--table-primary 表头标题变成绿色-->
                    <button type="button" class="btn btn-default" ng-click="select_userinfo()">查询权益</button>
                    <table ng-table="demo.UserinfoTableParams"
                           class="table table-condensed table-bordered table-striped">
                        <tr ng-repeat="row in $data">
                            {%raw%}
                            <td data-title="'账户'" sortable="'AccountId'">{{row.AccountId}}</td>
                            <td data-title="'品种'" sortable="'symbo'">{{row.symbo}}</td>
                            <td data-title="'账户总额'" sortable="'Fund'">{{row.Fund}}</td>
                            <td data-title="'合约类别'" sortable="'contract_type'">{{row.contract_type}}</td>
                            <td data-title="'合约ID'" sortable="'contract_id'">{{row.contract_id}}</td>
                            <td data-title="'持仓利润'" sortable="'PositionProfit'">{{row.PositionProfit}}</td>
                            <td data-title="'平仓利润'" sortable="'CloseProfit'">{{row.CloseProfit}}</td>
                            <td data-title="'手续费'" sortable="'Commission'">{{row.Commission}}</td>
                            <td data-title="'保证金'" sortable="'CurrMargin'">{{row.CurrMargin}}</td>
                            <td data-title="'冻结'" sortable="'FrozenCash'">{{row.FrozenCash}}</td>
                            <td data-title="'当前可用'" sortable="'Available'">{{row.Available}}</td>
                            <td data-title="'风险度'" sortable="'Risk'">{{row.Risk}}</td>
                            <!--<td data-title="'保证金率'" filter="{risk_rate: 'number'}" sortable="'risk_rate'">{{row.risk_rate}}</td>                过滤非常容易 -->
                            {%endraw%}
                        </tr>
                    </table>

                </div>
                <div class="tab-pane fade" id="ios">
                    <button type="button" class="btn btn-default" ng-click="select_position()">查询持仓</button>
                    <table ng-table="demo.PositionParams" class="table table-condensed table-bordered table-striped">
                        <tr ng-repeat="row in $data">
                            {%raw%}
                            <td data-title="'账户'" sortable="'AccountId'">{{row.AccountId}}</td>
                            <td data-title="'品种'" sortable="'InstrumentID'">{{row.InstrumentID}}</td>
                            <td data-title="'方向'" sortable="'Direction'">{{row.Direction}}</td>
                            <td data-title="'持仓数量'" sortable="'Position'">{{row.Position}}</td>
                            <td data-title="'价格'" sortable="'Price'">{{row.Price}}</td>
                            <td data-title="'可平仓位'" sortable="'bond'">{{row.bond}}</td>
                            <td data-title="'手续费'" sortable="'Commission'">{{row.Commission}}</td>
                            <td data-title="'昨仓'" sortable="'YdPosition'">{{row.YdPosition}}</td>
                            <td data-title="'今仓'" sortable="'TdPosition'">{{row.TdPosition}}</td>
                            <td data-title="'平仓利润'" sortable="'CloseProfit'">{{row.CloseProfit}}</td>
                            <td data-title="'持仓利润'" sortable="'PositionProfit'">{{row.PositionProfit}}</td>
                            <td data-title="'盈亏比'" sortable="'profit_lossratio'">{{row.profit_lossratio}}</td>
                            <td data-title="'强平价格'" sortable="'flatprice'">{{row.flatprice}}</td>
                            <td data-title="'保证金'" sortable="'Margin'">{{row.Margin}}</td>
                            <!--<td data-title="'保证金率'" filter="{risk_rate: 'number'}" sortable="'risk_rate'">{{row.risk_rate}}</td>                过滤非常容易 -->
                            {%endraw%}
                        </tr>
                    </table>
                </div>

{#                委托单   里面有两个可以展开#}
                <div class="tab-pane fade" id="orderlisttab">
                    <select ng-init="selectedName = names[0]" ng-model="selectedName"
                            ng-options="x for x in names"></select>
                    <button type="button" class="btn btn-default" ng-click="select_trade_orders(2)">手动查询okex成交记录</button>
{#                    <button type="button" class="btn btn-default" ng-click="select_trade_orders(1)">查询未成交记录</button>#}
                    <table ng-table class="table table-condensed table-bordered table-striped">
                        <tr ng-repeat="row in Ordersdatas | orderBy:'InsertTime'">
                            {%raw%}
                            <td data-title="'账户'" sortable="'AccountId'">{{row.AccountId}}</td>
                            <td data-title="'品种'" sortable="'InstrumentID'">{{row.InstrumentID}}</td>
                            <td data-title="'订单类型'" sortable="'Direction'">{{row.Direction}}</td>
                            <td data-title="'开平方式'" sortable="'Offset'">{{row.Offset}}</td>
                            <td data-title="'委托数量'" sortable="'Volume'">{{row.Volume}}</td>
                            <td data-title="'成交数量'" sortable="'TradeVolume'">{{row.TradeVolume}}</td>
                            <td data-title="'订单价格'" sortable="'LimitPrice'">{{row.LimitPrice}}</td>
                            <td data-title="'平均价格'" sortable="'AvgPrice'">{{row.AvgPrice}}</td>
                            <td data-title="'手续费'" sortable="'Fee'">{{row.Fee}}</td>
                            <td data-title="'订单状态'" sortable="'Status'">{{row.Status}}</td>
                            <td data-title="'状态描述'" sortable="'StatusMsg'">{{row.StatusMsg}}</td>
                            <td data-title="'策略描述'" sortable="'describe'">{{row.describe}}</td>
                            <td data-title="'合约面值'" sortable="'Unit_amount'">{{row.Unit_amount}}</td>
                            <td data-title="'杠杆倍数'" sortable="'Lever_rate'">{{row.Lever_rate}}</td>
                            <td data-title="'委托时间'" sortable="'InsertTime'">{{row.InsertTime}}</td>
                            <td data-title="'订单ID'" sortable="'OrderID'">{{row.OrderID}}
                                <button type="button" ng-if="row.Status=='等待成交'" class="btn btn-danger"
                                        ng-click="future_cancel(row.AccountId,row.InstrumentID,row.OrderID)">撤销
                                </button>
                            </td>
                            <!--<td data-title="'保证金率'" filter="{risk_rate: 'number'}" sortable="'risk_rate'">{{row.risk_rate}}</td>                过滤非常容易 -->
                            {%endraw%}
                        </tr>
                    </table>

                </div>

{#                成交记录#}
                 <div class="tab-pane fade" id="tradetab">
                    <button type="button" class="btn btn-default" ng-click="select_position()">查询持仓</button>
                    <table ng-table class="table table-condensed table-bordered table-striped">
                        <tr ng-repeat="row in Treaddatas | orderBy:'TradeTime'">
                            {%raw%}
                            <td data-title="'账户'" sortable="'AccountId'">{{row.AccountId}}</td>
                            <td data-title="'品种'" sortable="'InstrumentID'">{{row.InstrumentID}}</td>
                            <td data-title="'方向'" sortable="'Direction'">{{row.Direction}}</td>
                            <td data-title="'方向'" sortable="'Offset'">{{row.Offset}}</td>
                             <td data-title="'成交数量'" sortable="'Volume'">{{row.Volume}}</td>
                            <td data-title="'成交价格'" sortable="'Price'">{{row.Price}}</td>

                            <td data-title="'成交时间'" sortable="'TradeTime'">{{row.TradeTime}}</td>
                            <td data-title="'策略描述'" sortable="'describe'">{{row.describe}}</td>
                            <td data-title="'交易日'" sortable="'TradingDay'">{{row.TradingDay}}</td>
                            <td data-title="'订单id'" sortable="'OrderID'">{{row.OrderID}}</td>

                            <td data-title="'系统id'" sortable="'SysID'">{{row.SysID}}</td>

                            <!--<td data-title="'保证金率'" filter="{risk_rate: 'number'}" sortable="'risk_rate'">{{row.risk_rate}}</td>                过滤非常容易 -->
                            {%endraw%}
                        </tr>
                    </table>
                </div>




                 <div class="tab-pane fade" id="jmeter">
                    <p>备用1
                    </p>
                </div>


                <div class="tab-pane fade" id="ios">
                    <p>备用2
                    </p>
                </div>
            </div>
        </div>


    </div>



    <script type="text/javascript" charset="utf-8">
        //socke进行初始化
        var socket = io.connect('http://' + document.domain + ':' + location.port);

        socket.on('connect', function () {              //这是一个测试 可有可无
            console.log('scokio --前台链接')
            socket.emit('my event', {data: 'I m connectiond!'});
        });


        var stras = {{stras|tojson}};           //得到所有策略实例
        var strageties =
        {{ strageties|tojson }}  //得到所有策略类以及参数{'doubleMA':'MA5:5,MA10:10','TUPO':'Shang:10,Xia:10'}
        var allInstrument =
        {{allInstrument|tojson}}//从数据库得到所有合约以及最小跳
        var InvestorSetting =
        {{InvestorSetting|tojson}}
        var FuturesSetting =
        {{ FuturesSetting|tojson }}


        var allInstrumentNames = [];
        var stragetiesNames = [];


        //从策略对象得到所有策略名字
        for (i in strageties) {
            stragetiesNames.push(i);
        }
        //从合约对象得到所有合约名字
        for (var i = 0; i < allInstrument.length; i++) {
            allInstrumentNames.push(allInstrument[i])
        }
        //--------------------得到参数的详细 格式返回为 ”MA5“：5，“MA10”：20等  dict格式  提交到后台的时候比较方便直接使用
        function funParameterItem(var1) {
            var temp = [];
            for (i in var1) {
                temp.push('"' + i + '"' + ":" + var1[i])
            }
            return "{" + temp.toString() + "}";
        }


    </script>

{% endblock %}




